package com.hsh.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hsh.bean.User;
import com.hsh.dao.UserMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserService {

    @Resource
    private UserMapper userMapper;

    public Integer delete(Integer uid){
        return userMapper.deleteByPrimaryKey(uid);
    }

    public Integer update(User user){
        return userMapper.updateByPrimaryKey(user);
    }

    public Integer add(User user){
        return userMapper.insert(user);
    }

    /**
     * 分页模糊查询
     * @param user
     * @param pageNumber
     * @param pageSize
     * @return
     */
    public PageInfo<User> findUserByPage(User user, Integer pageNumber, Integer pageSize){
        System.out.println(user);
        return PageHelper.startPage(pageNumber, pageSize).doSelectPageInfo(
                ()->{userMapper.findAllByUser(user);}
        );
    }

    public User findById(Integer uid){
        return userMapper.selectByPrimaryKey(uid);
    }

    public List<User> login(User user){
        return userMapper.login(user);
    }
}

